#include "CCEGLView.h"
#include "AppDelegate.h"

#include "Global.h"
#include "dungeons/utils/LocalString.h"
#include "dungeons/model/proxy/DungeonsProxy.h"
#include "dungeons/model/proxy/ItemProxy.h"
//#include "dungeons/model/proxy/ProxyManager.h"
#include "dungeons/model/static/StaticDungeons.h"
#include "dungeons/model/static/StaticItem.h"
#include "dungeons/net/NetController.h"
#include "dungeons/view/component/scene/SceneManager.h"
#include "dungeons/view/component/dialog/PopupManager.h"

#include "dungeons/utils/CommonHelper.h"
#include "view/component/CommonNotify.h"

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
}

bool AppDelegate::applicationDidFinishLaunching()
{
	// initialize director
	CCDirector *pDirector = CCDirector::sharedDirector();
	pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

	// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
	//pDirector->enableRetinaDisplay(true);

	// turn on display FPS
	//pDirector->setDisplayStats(true);

	// set FPS. the default value is 1.0/60 if you don't call this
	pDirector->setAnimationInterval(1.0 / 60);
    
//	NetController::getSingletonPtr()->init("http://cv2473.d1.myidc.cc/server/www/amf/gateway.php");
//    NetController::getSingletonPtr()->init("http://cv2473.d1.myidc.cc/server/www/amf/gateway.php");
//    NetController::getSingletonPtr()->init("http://cv2473.d1.myidc.cc/lance_server/www/amf/gateway.php");
    NetController::getSingletonPtr()->init("http://cv2803.d1.myidc.cc/lance_server/www/amf/gateway.php");
    
    
	/*CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary()->registerCCNodeLoader("HomeScene", CCNodeLoader::loader());
	CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary()->registerCCNodeLoader("MainMenu", CCNodeLoader::loader());
	CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary()->registerCCNodeLoader("UserInfo", CCNodeLoader::loader());*/

	//CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary()->registerCCNodeLoader("HomeScene", HomeSceneLoader::loader());
	//CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary()->registerCCNodeLoader("UserInfo", UserInfoLoader::loader());
	//CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary()->registerCCNodeLoader("MainMenu", MainMenuLoader::loader());
	//CCNode* pRootNode = CCNode::create();
	//CCNode* pNode = ReadNode("HomeScene.ccbi", "CCNode", pRootNode);
	//CCNode* pNode = ReadNode("MainMenu.ccbi", "CCNode", pRootNode);

	StaticDungeons::getSingletonPtr()->parse();
	StaticItem::getSingletonPtr()->parse();
	CommonNotify::getSingletonPtr()->registerNotify();
	Framework::getSingletonPtr()->init();	
	Framework::getSingletonPtr()->setStateManager(SceneManager::getSingletonPtr());
	Framework::getSingletonPtr()->setDialogManager(PopupManager::getSingletonPtr());
	//Framework::getSingletonPtr()->changeState("DungeonsScene");
	//Framework::getSingletonPtr()->changeState("TestScene");
	Framework::getSingletonPtr()->changeState("HomeScene");
	//Framework::getSingletonPtr()->popup("EquipMergeDialog", NULL, 0, 150);
    
//    NetController::getSingletonPtr()->regist(getDeviceID(), 1);
//    NetController::getSingletonPtr()->regist("sunbo_05", 1);
    NetController::getSingletonPtr()->gameInit();
	return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
	CCDirector::sharedDirector()->stopAnimation();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
	CCDirector::sharedDirector()->startAnimation();
}
